from PyQt4.QtGui import QDialog
from PyQt4.QtGui import QGridLayout, QVBoxLayout
from PyQt4.QtGui import QPainter, QPixmap

from views.widgets.boardView import BoardView
from views.widgets.pushButton import PushButton


class LocalGameView(QDialog):
    def __init__(self, parent=None):
        super(LocalGameView, self).__init__(parent)
        self.setWindowTitle('Game')
        self.resize(650, 700)
        # widgets
        self.boardView = BoardView(self)
        self.newGameButton = PushButton('New Game')
        self.retractButton = PushButton('Retract')
        self.remindButton = PushButton('Remind')
        self.returnButton = PushButton('Return')
        # Layout
        self.buttonBox = QGridLayout()
        self.buttonBox.addWidget(self.newGameButton, 0, 0)
        self.buttonBox.addWidget(self.retractButton, 0, 1)
        self.buttonBox.addWidget(self.remindButton, 1, 0)
        self.buttonBox.addWidget(self.returnButton, 1, 1)
        self.mainLayout = QVBoxLayout(self)
        self.mainLayout.addWidget(self.boardView)
        self.mainLayout.addLayout(self.buttonBox)
        self.setLayout(self.mainLayout)

    def paintEvent(self, event):
        painter = QPainter(self)
        self.drawBackground(painter)
        self.boardView.paint(painter)

    def mouseReleaseEvent(self, event):
        # print(event.x(), event.y())
        self.boardView.click(event)

    def drawBackground(self, painter):
        pixmap = QPixmap(":/background/background.png")
        painter.drawPixmap(0, 0, pixmap)
